// 引入
import { Banner, shop, notice, adPosition, goods } from "../../utils/http"


Page({
  onShareAppMessage() {
    return {
      title: 'swiper',
      path: 'page/component/pages/swiper/swiper'
    }
  },

  data: {
    startSwiper: [],
    adPositions: [],
    shops: [],
    notices: [],
    shopzb: [],
    miaoshas: [],
    goodss: [],
    goodsbp: [],
    kanjia: [],
    pingtuan: [],
  },
    // 跳转详情
    tiaoz(e){
      console.log(e);
      let id=e.currentTarget.dataset.id
      wx.navigateTo({
        url: `/pages/detail/detail?id=${id}`,
      })
    },
    // 跳分类
  gotosfl(e){
    console.log(e);
    let id=e.currentTarget.dataset.id
    wx.reLaunch({
      url: `/pages/classify/classify?id=${id}`
    })
    // console.log(id);
  },
  onLoad: function (options) {
    let { startSwiper, shops, notices, shopzb, adPositions, miaoshas, goodss, goodsbp, kanjia, pingtuan } = this.data;
    Banner().then((res) => {
      console.log(res)
      if (res.msg == "success") {
        res.data.map((v) => {
          if (v.type == "index") {
            startSwiper.push(v)
          }
        })
      }
      if (res.msg == "livelist") {
        res.data.map((v) => {
          if (v.type == "index") {
            shopzb.push(v)
          }
        })
      }
      this.setData({
        startSwiper
      })
    })
    shop().then((res) => {
      console.log(res);
      if (res.msg == "success") {
        shops = res.data
        // console.log(this.data.shop);
      }
      this.setData({
        shops
      })
    })
    notice().then((res) => {
      console.log(res);
      if (res.msg == "success") {
        notices = res.data
        // console.log(this.data.shop);
      }
      this.setData({
        notices
      })
    })
    adPosition({
      keys: "index-live-pic"
    }).then((res) => {
      console.log(res);
      if (res.msg == "success") {
        adPositions = res.data
        // console.log(this.data.shop);
      }
      this.setData({
        adPositions
      })
    })
    goods().then((res) => {
      console.log(res.data);
      goodss = res.data.result;
      goodss.forEach((v) => {
        if (v.miaosha === true) {
          miaoshas.push(v)
        }
      })
      goodss.forEach((v) => {
        if (v.kanjia === true) {
          kanjia.push(v)
        }
      })

      goodss.forEach((v) => {
        goodsbp.push(v)
      })
      goodss.forEach((v) => {
        if (v.pingtuan === true) {
          pingtuan.push(v)
        }
      })
      goodsbp.reverse()
      goodsbp.splice(2)
      miaoshas.reverse()
      goodss.reverse();
      miaoshas.splice(2);
      this.setData({
        miaoshas,
        goodsbp,
        kanjia,
        goodss,
        pingtuan,
      })
      console.log(pingtuan);
    })
  }
})